// p2pserver.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <signal.h>
#include <conio.h>
#include "p2psvrapp.h"

static void sig_int_stop_server(int signo)
{
    signo;
    CP2PSvrApp::Instance()->Stop();
    CP2PSvrApp::Instance()->DestoryInstance();
    exit(0);
}

int _tmain(int argc, _TCHAR* argv[])
{
    if (signal(SIGINT, sig_int_stop_server) == SIG_ERR)
    {
        return -1;
    }

    char szCMD[1024] = {0};

    if (!CP2PSvrApp::CreateInstance())
    {
        return -1;
    }
    else
    {
        if (!CP2PSvrApp::Instance()->Start())
        {
            CP2PSvrApp::DestoryInstance();
            return -1;
        }
    }

    while (!CP2PSvrApp::Instance()->is_closing())
    {
        if (_kbhit())
        {
            scanf_s("%s", szCMD, sizeof(szCMD));
            if (!_stricmp("stop", szCMD) || !_stricmp("2", szCMD))
            {
                CP2PSvrApp::Instance()->Stop();
                break;
            }
        }

        Sleep(1);
    }
	return 0;
}

